package com.push.xu.xpush.util;

import com.push.xu.xpush.constant.SystemTarget;

import java.io.IOException;


/**
 * Created by xu on 2018/1/18.
 */

public class RomUtil {
    private static SystemTarget mTarget = null;
    private static final String KEY_EMUI_VERSION_CODE = "ro.build.version.emui";
    private static final String KEY_EMUI_API_LEVEL = "ro.build.hw_emui_api_level";
    private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
    private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
    private static final String KEY_MIUI_HANDY_MODE_SF = "ro.miui.has_handy_mode_sf";
    private static final String KEY_MIUI_REAL_BLUR = "ro.miui.has_real_blur";


    /**
     * 华为rom
     *
     * @return
     */
    public static boolean isEMUI() {
        try {
            final BuildProperties prop = BuildProperties.newInstance();
            return prop.containsKey(KEY_EMUI_VERSION_CODE) || prop.containsKey(KEY_EMUI_API_LEVEL);
        } catch (final IOException e) {
        	String s1 = android.os.Build.BRAND;
    		String s2= android.os.Build.MANUFACTURER;
        	if(s1.equals("HUAWEI")||s2.equals("HUAWEI")) {
        		return true;
        	}
            return false;
        }
    }

    /**
     * 小米rom
     *
     * @return
     */

    public static boolean isMIUI() {
        try {
            final BuildProperties prop = BuildProperties.newInstance();
            /*String rom = "" + prop.getProperty(KEY_MIUI_VERSION_CODE, null) + prop.getProperty(KEY_MIUI_VERSION_NAME, null)+prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null);
            Log.d("Android_Rom", rom);*/
            return prop.containsKey(KEY_MIUI_VERSION_CODE)
                    || prop.containsKey(KEY_MIUI_VERSION_NAME)
                    || prop.containsKey(KEY_MIUI_REAL_BLUR)
                    || prop.containsKey(KEY_MIUI_HANDY_MODE_SF);
        } catch (final IOException e) {
            return false;
        }
    }

    public static SystemTarget rom() {
        if (mTarget != null)
            return mTarget;

        if (isMIUI()) {
            mTarget = SystemTarget.MIUI;
            return mTarget;
        }
        if (isEMUI()) {
            mTarget = SystemTarget.EMUI;
            return mTarget;
        }

        mTarget = SystemTarget.JPUSH;
        return mTarget;
    }

}
